<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>预约列表</title>
<link href="${pageContext.request.contextPath}/page/admin/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/page/admin/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
<script src="${pageContext.request.contextPath}/page/admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script src="${pageContext.request.contextPath}/static/lib/layer/2.4/layer.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/jquery.sPage.css">
<script src="${pageContext.request.contextPath}/static/js/jquery.sPage.js"></script>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 预约管理 <span class="c-gray en">&gt;</span> 预约列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l"> 

			<a href="javascript:" onclick=approveByquery() class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i>批量审核</a>
 			<a href="javascript:" onclick="deleteByquery()" class="btn btn-danger radius"><i class="icon-trash"></i><i class="Hui-iconfont">&#xe6e2;</i> 批量取消</a>
		</span>	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<select id="typeSelect">
			<option value="0">请选择考试类型</option>
			<c:forEach items="${typeList}" var="type" varStatus="status">
				<option value="${status.count}">${type.typeName}</option>
			</c:forEach>
		</select>
		<select id="subjectSelect">
			<option value="0">请选择科目</option>
			<option value="1">科目一</option>
			<option value="2">科目二</option>
			<option value="3">科目三 道路驾驶技能考试</option>
			<option value="3">科目三 安全文明驾驶常识考试</option>
		</select>
		 &nbsp;&nbsp;&nbsp;&nbsp;日期范围：
			<input type="text" onfocus="WdatePicker({ maxDate:'\'2050-12-31\'}'})" id="logmin" class="input-text Wdate" style="width:120px;" autocomplete="off">
			-
			<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d'})" id="logmax" class="input-text Wdate" style="width:120px;" autocomplete="off">
			<input type="text" name="" id="idNumber" placeholder="身份证号码" style="width:250px" class="input-text">
			<button name="" onclick="search(1,10)" id="search" class="btn btn-success" type="button"><i class="Hui-iconfont">&#xe665;</i>搜索</button>
		
		
	</div>
	
	<div class="mt-20">
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				        <th width="20">ID</th>
						<th width="60">用户名</th>
						<th width="150">身份证号码</th>
						<th width="60">手机</th>
						<th width="60">类型</th>
						<th width="60">科目</th>
						<th width="60">场地</th>
						<th width="60">预约日期</th>
						<th width="60">预约排名</th>
						<th width="60">考试日期</th>
						<th width="60">时间段</th>
						<th width="60">预约状态</th>
						<th width="50">选项</th>
			</tr>
		</thead>
		<tbody id="tbody">
			
		</tbody>
		
	</table>
	<div id="myPage" align="center" class="demo"></div>
	</div>
	
</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/page/admin/lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript">
$(function(){
	search(1,10);
});
function search(page,pageSize){
	var typeName;
	var subject;
	var startTime = $("#logmin").val();
	var endTime = $("#logmax").val();
	var idNumber = $("#idNumber").val();
	if(0==$("#typeSelect").val()){
		typeName = '';
	} else {
		typeName = $("#typeSelect option:selected").text(); 
	}
	if(0==$("#subjectSelect").val()){
		subject = '';
	} else {
		subject = $("#subjectSelect option:selected").text(); 
	}
	
	showReserve(page,pageSize,idNumber,startTime,endTime,typeName,subject); //搜索显示预约

}
	
function showReserve(page,pageSize,idNumber,startTime,endTime,typeName,subject){ //点击分页按显示预约信息
	$.ajax({
		url:"${pageContext.request.contextPath}/ReserveManage/getReserve",
		type:"get",
		dataType:"json",
		data:{"state":1,"page":page,"pageSize":pageSize,"idNumber":idNumber,"startTime":startTime,"endTime":endTime,"typeName":typeName,"subject":subject},
		async:false,
		success:function(paging){
			$("#tbody").html("");
			$.each(paging.list,function(index,reserve){
				$("#tbody").append(
						'<tr class="text-c">'+
						'<td><input class="checkbox" type="checkbox" name=""></td>'+
						'<td>'+reserve.id+'</td>'+
						'<td>'+reserve.user.userName+'</td>'+
						'<td>'+reserve.user.idNumber+'</td>'+
						'<td>'+reserve.user.tel+'</td>'+ 
						'<td>'+reserve.session.type.typeName+'</td>'+
						'<td>'+reserve.session.subject+'</td>'+ 
						'<td>'+reserve.session.place+'</td>'+ 
						'<td>'+reserve.reserveTime+'</td>'+ 
						'<td>'+reserve.rank+'</td>'+
						'<td>'+reserve.session.dates+'</td>'+
						'<td>'+reserve.session.times+'</td>'+
						'<td class="state">'+reserve.state+'</td>'+
						'<td><a style="text-decoration:none" class="ml-5" onclick=reserve_approve('+reserve.id+') title="审核通过">'+
						'<i class="Hui-iconfont">&#xe676</i></a>'+ 
						'<a style="text-decoration:none" class="ml-5" onclick=reserve_del(this,'+reserve.id+') title="删除">'+
						'<i class="Hui-iconfont">&#xe6e2;</i></a>'+
						'</td>'+
					'</tr>'
						
				);
			});
			//alert('totalCount='+paging.totalCount);
			if(paging.totalCount!=0){
				sPageInit(paging.totalCount,paging.currentPage,paging.pageSize); //填充分页条信息	
			} else {
				sPageInit(1,paging.currentPage,paging.pageSize); //填充分页条信息
			}
			changeState();
		},
		error:function(){
			alert('error');
		}
	});
}
function sPageInit(total,page,pageSize){ //page当前页，total总条数，pageSize页面大小 
	$("#myPage").sPage({ //对分页条进行数据填充
  	    page:page,//当前页码，必填   
        total:total,//数据总条数，必填    
        pageSize:pageSize,//每页显示多少条数据，默认10条
        showTotal:true,//是否显示总条数，默认关闭：false
        totalTxt:'共'+total+'条',//数据总条数文字描述，{total}为占位符，默认"共{total}条" 
        showSkip:true,//是否显示跳页，默认关闭：false
        showPN:true,//是否显示上下翻页，默认开启：true
        prevPage:"上一页",//上翻页文字描述，默认“上一页”
        nextPage:"下一页",//下翻页文字描述，默认“下一页”
        backFun:function(page){
        	search(page,pageSize);
        	//showReserve(page,pageSize,idNumber,startTime,endTime,typeName,subject);
        }
	});
}
function changeState(){ //把状态数字改为中文
	var ele = $(".state");
	$.each(ele,function(index,value){
		if ($(this).text()=='2'){
			$(this).text('预约成功');	
		}
		if ($(this).text()=='0'){
			$(this).text('预约失败');	
		}
		if ($(this).text()=='1'){
			$(this).text('审核中');	
		}
		if ($(this).text()=='4'){
			$(this).text('审核通过');	
		}
		
	});
	
}
function deleteByquery(){ //批量取消
	var ele = $(".checkbox"); //获取所以复选框对象
	var list = [];
	$.each(ele,function(index,value){
		if($(this).is(':checked')){ //如果复选框被选中		
			list[list.length] = $(this).parent().next().text(); //填进数组
		}
	});
	if(0==list.length){
		layer.msg('至少选择一个用户',{icon:5,time:2000});
	} else {
		//先询问是否删除
		if(confirm('您确定要取消吗?')){		 
			$.ajax({
				url:"${pageContext.request.contextPath}/ReserveManage/deleteReserveByQuery",
				type:"get",
				dataType:"json",
				data:{"reserveIdList":JSON.stringify(list)},//预约ID列表
				success:function(data){
					if(1==data.res){
						layer.msg('删除成功',{icon:1,time:2000});	
						location.reload();
					}
								
				},
				error:function(){
					alert('error');
				}
			});
		}
	}
}
function approveByquery(){
	var ele = $(".checkbox"); //获取所以复选框对象
	var list = [];
	$.each(ele,function(index,value){
		if($(this).is(':checked')){ //如果复选框被选中		
			list[list.length] = $(this).parent().next().text(); //填进数组
		}
	});
	if(0==list.length){
		layer.msg('至少选择一个用户',{icon:5,time:2000});
	} else {
		//先询问是否删除
		if(confirm('您确定要审核通过吗?')){		 
			$.ajax({
				url:"${pageContext.request.contextPath}/ReserveManage/approveReserveByQuery",
				type:"get",
				dataType:"json",
				data:{"reserveIdList":JSON.stringify(list)},//预约ID列表
				success:function(data){
					if(1==data.res){
						layer.msg('审核成功',{icon:1,time:2000});	
						location.reload();
					}
								
				},
				error:function(){
					alert('error');
				}
			});
		}
	}
}
function reserve_approve(reserveId){ 
	if(confirm('您确定要审核通过吗?')){
		$.ajax({
			type:"get",
			url:"${pageContext.request.contextPath}/ReserveManage/approveReserve",
			dataType:"json",
			data:{"reserveId":reserveId},
			async:false,
			success: function(data){
				layer.msg('已审核!',{icon:1,time:1000});
				location.reload();
			},
			error:function(data) {
				alert('error');
			}
		});
}
}
/*学生-删除*/
function reserve_del(obj,reserveId){
		if(confirm('您确定要取消吗?')){
				$.ajax({
					type:"get",
					url:"${pageContext.request.contextPath}/ReserveManage/deleteReserve",
					dataType:"json",
					data:{"reserveId":reserveId},
					async:false,
					success: function(data){
						layer.msg('已删除!',{icon:1,time:1000});
						location.reload();
					},
					error:function(data) {
						alert('error');
					}
				});
		}
}

/*用户-添加*/
function member_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*用户-查看*/
function member_show(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*用户-编辑*/
function member_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*密码-修改*/
function change_password(title,url,id,w,h){

	layer_show(title,url,w,h);	
}

</script> 
</body>
</html>